#define _CRT_SECURE_NO_WARNINGS 1


#include<iostream>
using namespace std;
int n, m;
const int N = 1e3 + 10;
char ans[N][N];
int main()
{
    cin >> n >> m;
    for (int i = 1;i <= n;i++)
    {
        for (int j = 1;j <= m;j++)
        {
            cin >> ans[i][j];
        }
    }
    for (int i = 1;i <= n;i++)
    {
        for (int j = 1;j <= m;j++)
        {
            if (ans[i][j] == '*')
                cout << '*';
            else
            {
                int count = ((ans[i - 1][j] == '*') + (ans[i - 1][j - 1] == '*')
                    + (ans[i - 1][j + 1] == '*') + (ans[i][j + 1] == '*')
                    + (ans[i][j - 1] == '*') + (ans[i + 1][j] == '*')
                    + (ans[i + 1][j + 1] == '*') + (ans[i + 1][j - 1] == '*'));
                cout << count;
            }
        }
        printf("\n");
    }
    return 0;
}